/**
 * @param {Object} file 文件下载链接
 * @param {Object} fileName 文件名称
 */
export function downloadFileTools(file, fileName) {
	return new Promise((resolve, reject) => {
		const fileSplitList = file.split('/')
		const fileExtension = fileSplitList[fileSplitList.length - 1].split('.')[1]
		uni.downloadFile({
			url: file,
			success: res => {
				if (res.statusCode === 200) {
					uni.saveFile({
						tempFilePath: res.tempFilePath,
						filePath: uni.env.USER_DATA_PATH +
							`/${fileName}.${fileExtension}`,
						success: data => {
							resolve(data)
						},
						fail: err => {
							reject(err)
						}
					})
				}
			},
			fail: (err) => {
				reject(err)
			}
		});
	})
}